//
//  TTCustomGoodsTextFieldViewCell.m
//  TaoTuo
//
//  Created by apple on 2020/11/19.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTCustomGoodsTextFieldViewCell.h"

@interface TTCustomGoodsTextFieldViewCell ()
/// 标题
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UITextField *contentTF;
/// 提示按钮
@property (nonatomic, strong) UIButton *infoBtn;

/// 覆盖在上面的按钮
@property (nonatomic, strong) UIButton *aboveBtn;

@end

@implementation TTCustomGoodsTextFieldViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupSubviews];
        @weakify(self)
        [self.contentTF.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
            @strongify(self)
            self.model.content = x;
            
        }];
        
    }
    return self;
}

- (void)setModel:(TTCustomGoodsTFModel *)model
{
    _model = model;
    
    self.titleLabel.text = model.title;
    self.contentTF.text = model.content;
    [self.infoBtn setTitle:model.infoStr forState:UIControlStateNormal];
    
    self.infoBtn.hidden = model.infoStr.length == 0;
    
    self.aboveBtn.hidden = !model.notEdit;
    
}

- (void)clickBtn
{
    if (self.model.aboveBtnBlock) {
        self.model.aboveBtnBlock();
    }
    
}

- (void)setupSubviews
{
    _titleLabel = [UILabel labelWithTitle:@"" color:UIColorHex(333333) fontSize:14];
    [self.contentView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.left.mas_equalTo(15);
    }];
    
    _contentTF = [[UITextField alloc] init];
    _contentTF.placeholder = @"";
    _contentTF.font = [UIFont systemFontOfSize:14];
    _contentTF.textColor = UIColorHex(333333);
    _contentTF.backgroundColor = UIColorHex(f2f2f2);
    _contentTF.borderStyle = UITextBorderStyleRoundedRect;
    [self.contentView addSubview:_contentTF];
    [_contentTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).offset(15);
        make.left.equalTo(self.titleLabel);
        make.right.equalTo(self.contentView.mas_right).offset(-15);
        make.height.mas_equalTo(30);
    }];
    
    _aboveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_aboveBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_aboveBtn];
    [_aboveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(_contentTF);
    }];
    
    
    _infoBtn = [UIButton createButtonWithTitle:@"" titleColor:UIColorHex(#FC832A) titleFont:[UIFont systemFontOfSize:12] backgroundColor:nil target:nil action:nil];
    [_infoBtn setImage:[UIImage imageNamed:@"hintgantanhao"] forState:UIControlStateNormal];
    _infoBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.contentView addSubview:_infoBtn];
    [_infoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentTF.mas_bottom).offset(10);
        make.left.equalTo(self.titleLabel);
    }];
    
}


@end
